*************************************************************************************
** TITLE: Citizen Cooperation with the Police: Evidence from Guatemala
** Date: 08/19/2022
** Authors: Elaine Denny, David Dow, Wayne Pitts, Erik Wibbels
*************************************************************************************

** Set directory
cd "~\Dropbox\Community Policing MPP Paper\Code\replication\"

set more off
set scheme plottig

** Load data
use "mpp_obs_data.dta", clear

** Standardize main vars
local vars_st protect_wit drug_dealing_rescale shooting_rescale neighbors_trust_rescale fight_crime assets_total age education homicide_rate2018 pol_legit_rescale
foreach v in `vars_st' {
	quietly egen z`v' = std(`v')
}

** Label standardized vars
label variable zfight_crime "PNC Crime Effectiveness"
label variable zprotect_wit "PNC Protects Witnesses"
label variable zdrug_dealing_rescale "Drug Trafficking Presence"
label variable zshooting_rescale "Shootings in Community"
label variable zhomicide_rate2018 "Homicide Rate (2018)"
label variable zneighbors_trust_rescale "Trust Neighbors"
label variable zassets_total "Assets (Count)"
label variable zassets_total "Assets"
label variable zeducation "Education"
label variable zage "Age"
label variable zpol_legit_rescale "Police Legitimacy"


** regression variables
local reg_survey police_where1 language_indigenous zprotect_wit zdrug_dealing_rescale zshooting_rescale crime_victim_any zneighbors_trust_rescale zfight_crime police_active_4
local reg_admin police_where1 language_indigenous zprotect_wit zdrug_dealing_rescale zhomicide_rate2018 crime_victim_any zneighbors_trust_rescale zfight_crime police_active_4
local demos zassets_total zage gender zeducation

** Table 3: Correlates of Citizen Reporting to the Police 
** Model 1 
eststo clear
eststo: quietly logistic police_help `reg_survey' `demos', cluster(community_id)

** Model 2 - Uses admin data on homicide rate
eststo: quietly logistic police_help `reg_admin' `demos', cluster(community_id)

** Model 3 with interaction
eststo: quietly logistic police_help police_where1##language_indigenous zprotect_wit zdrug_dealing_rescale zhomicide_rate2018 crime_victim_any zneighbors_trust_rescale zfight_crime police_active_4 `demos', cluster(community_id)

esttab using table_1.tex, label mtitle("Contact Police" "Contact Police" "Contact Police") title(Correlates of Citizen Reporting to the Police\label{tab:logit_main}) star(+ 0.10 * 0.05 ** 0.01 *** 0.001) nobaselevels replace eform


** Figure A8: Average Marginal Effects on Contacting Police (Logit Model 1)
eststo clear
quietly logistic police_help `reg_survey' `demos', cluster(community_id)
margins, dydx(*) post
coefplot, xtitle("Average Marginal Effects on Pr(Contact)") drop(_cons) xline(0) plotregion(margin(medlarge)) grid(none) headings(police_where1 = "{bf:Alignment of Interests}" zprotect_wit = "{bf:Costs of Reporting}" zshooting_rescale = "{bf:Costs of Crime}" zneighbors_trust_rescale = "{bf:Community Cooperation}" zfight_crime = "{bf:Perceived Police Efficacy}" zassets_total = "{bf: Demographic Controls}")
graph export fig_a8_ame.pdf, replace

** Figure A9: Plot marginal effects for interaction between police origins and language
label define language 0 "Spanish" 1 "Indigenous" 
label values language_indigenous language 
label define police_where1 0 "Police From Here" 1 "Police From Outside" 
label values police_where1 police_where1 

quietly logistic police_help police_where1##language_indigenous zprotect_wit zdrug_dealing_rescale zhomicide_rate2018 crime_victim_any zneighbors_trust_rescale zfight_crime police_active_4 `demos', cluster(community_id)
margins, dydx(police_where1) over(language_indigenous)
marginsplot, title(Average Marginal Effects of Police Outsiders by Language) recast(scatter) xscale(range(-.25 1.25))
graph save fig_a9_origins_identity.gph, replace
graph export fig_a9_origins_identity.pdf, replace


* Table A4: Correlates of Perceptions of Police in Guatemala
eststo clear
eststo: reg police_respect `reg_admin' `demos', cluster(community_id)
eststo: reg trust_pnc_all  `reg_admin' `demos', cluster(community_id)
esttab using table_a4.tex, label mtitle("Police Respect" "Trust Police") title(Correlates of Perceptions of Police in Guatemala\label{tab:local_regs}) star(+ 0.10 * 0.05 ** 0.01 *** 0.001) replace


* Table A5: Robustness checks - Correlates of Civilian Reporting to the Police
local non_int zprotect_wit zdrug_dealing_rescale zshooting_rescale crime_victim_any zneighbors_trust_rescale zfight_crime police_active_4

eststo clear
eststo: quietly logistic police_help `reg_survey' zpol_legit_rescale `demos', cluster(community_id)

eststo: quietly logistic police_help police_where1##language_indigenous `non_int' zpol_legit_rescale `demos', cluster(community_id)

eststo: quietly logistic police_help `reg_survey' zpol_legit_rescale `demos' i.municipio_id, cluster(community_id)

eststo: quietly logistic police_help police_where1##language_indigenous `non_int' zpol_legit_rescale `demos' i.municipio_id, cluster(community_id)

esttab using table_a5.tex, label mtitle("" "" "" "") title(Correlates of Citizen Reporting to the Police\label{tab:logit_muni}) star(+ 0.10 * 0.05 ** 0.01 *** 0.001) drop(*municipio_id) nobaselevels replace eform
